
/*
The following codes replicate Tables 8 and 9

*/





******************Table 8***********************************
******************Table 8***********************************
******************Table 8***********************************


cd "D:\Nanjing\2020\wage gap\Replication"
use "labor-basic-tpu-reg-1.dta",clear

bysort newid: egen exp_max=max(export_intensity)
drop if exp_max==1  
gen ddd_export=did * d_export
* xtset newid t
 egen provyear=group(province  t)
 egen ind2year=group(ind2_adj  t)
 egen owneryear=group(QiuType  t)
 egen provowneryear=group(province QiuType  t)
 egen ind4year=group(ind4_adj  t)

capture drop ddd_export
gen indc_export=0
gen indc_export_new=0
replace indc_export=1 if export_intensity>0&(t==1999|t==2000|t==1998|t==2001)
replace indc_export_new=1 if export_intensity>0&(t>=2002)

bysort newid: egen indc_export1=max(indc_export)
bysort newid: egen indc_export2=max(indc_export_new)




gen ddd_export=did*indc_export1
gen ddd_export2=did*indc_export2
/*
bysort newid post: gen indc_n=_n==1
bysort newid: egen indc_exist=sum(indc_n)
*/



*egen ub1=pctile(absG),p(99)
*egen lb1=pctile(absG),p(1)

*replace did=0 if indc_export1==1
gen exp_post=indc_export1*post
gen exp_tpu=indc_export1*tpu

*drop if indc_export1==0&export_intensity>0
*--------------------------------------------------------------------

gen lnabsG_gdp=ln(absG_gdp)

winsor2 tfp_op lnabsG_gdp lnage  finance2  lnkL rate , replace cuts(1 99) trim
winsor2 lnRD, replace cuts(0 99) trim
drop if VMPL<0


*******************************************************************************************************
*8.1 (column 1) firm and year fixed effects
reghdfe lnabsG_gdp ddd_export did Llnl  Ltfp_op   Llnage  LlnkL  LlnRD    export_intensity Lfinance2 exp_post ///
 Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind ,  ///
absorb(t newid) cluster (ind4year)   
 *----------------------------------------------------------------------------------------------------------
 *8.2 (column 2) prov-year and firm fe
reghdfe lnabsG_gdp ddd_export did Llnl  Ltfp_op   Llnage  LlnkL  LlnRD    export_intensity Lfinance2 exp_post ///
 Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind ,  ///
absorb(provyear newid) cluster (ind4year)   
 *----------------------------------------------------------------------------------------------------------
 *8.3 (column 3) owner-year and firm fe
reghdfe lnabsG_gdp ddd_export did Llnl  Ltfp_op   Llnage  LlnkL  LlnRD    export_intensity Lfinance2 exp_post ///
 Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind ,  ///
absorb(owneryear newid) cluster (ind4year)   
 
 *----------------------------------------------------------------------------------------------------------
 *8.4 (column 4) prov-year+owner-year and firm fe
reghdfe lnabsG_gdp ddd_export did Llnl  Ltfp_op   Llnage  LlnkL  LlnRD    export_intensity Lfinance2 exp_post ///
 Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind ,  ///
absorb(provyear owneryear newid) cluster (ind4year)   
 *----------------------------------------------------------------------------------------------------------
 *8.5 (column 5) industry-year and firm fe
reghdfe lnabsG_gdp ddd_export did Llnl  Ltfp_op   Llnage  LlnkL  LlnRD    export_intensity Lfinance2 exp_post ///
 Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind ,  ///
absorb(ind2year newid) cluster (ind4year)   
 
*----------------------------------------------------------------------------------------------------------
* 8.6 (column 6) new exporters
reghdfe lnabsG_gdp ddd_export2 did Llnl  Ltfp_op   Llnage  LlnkL  LlnRD  exp_post  export_intensity Lfinance2 exp_post ///
 Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind if indc_export1==0,  ///
absorb(t newid) cluster (ind4year)   
*********************************************************************************
















******************Table 9***********************************
******************Table 9***********************************
******************Table 9***********************************





cd "D:\Nanjing\2020\wage gap\Replication"
use "labor-basic-tpu-reg-1.dta",clear

gen VMPK=capitale*(y_ind_add1/k)



*1. generate capital category:
bysort id: gen indc_n=_n==1
gen m_k=k if indc_n==1
bysort id: egen M_k=max(m_k)

egen p1=pctile(M_k), p(25)
egen p2=pctile(M_k), p(50)
egen p3=pctile(M_k), p(75)
gen size_k=0
replace size_k=1 if M_k<=p1
replace size_k=2 if M_k>p1&M_k<p2
replace size_k=3 if M_k>p2&M_k<p3
replace size_k=4 if M_k>p3

 bysort t indc: egen agg_l=sum(n)
 gen l_s=n/agg_l
 
*2. generate average rental rate in each category:
bysort city ind4_adj QiuType size_k t: egen r_rate=sum(l_s*VMPK) if inv>0
*bysort county ind4_adj QiuType size_k t: egen r_rate=mean(VMPK) if inv>0


* 3. gap measured in capital:

gen gdp_def=1
replace gdp_def=1.077 if t==1999
replace gdp_def=1.077*1.085 if t==2000
replace gdp_def=1.077*1.085*1.083 if t==2001
replace gdp_def=1.077*1.085*1.083*1.091 if t==2002
replace gdp_def=1.077*1.085*1.083*1.091*1.10 if t==2003
replace gdp_def=1.077*1.085*1.083*1.091*1.10*1.201 if t==2004
replace gdp_def=1.077*1.085*1.083*1.091*1.10*1.201*1.114 if t==2005
replace gdp_def=1.077*1.085*1.083*1.091*1.10*1.201*1.114*1.127 if t==2006
replace gdp_def=1.077*1.085*1.083*1.091*1.10*1.201*1.114*1.127*1.142 if t==2007

/*
gen gdp_def=1
replace gdp_def=1.063 if t==1999
replace gdp_def=1.177 if t==2000
replace gdp_def=1.302 if t==2001
replace gdp_def=1.428 if t==2002
replace gdp_def=1.819 if t==2003
replace gdp_def=1.899 if t==2004
replace gdp_def=2.198 if t==2005
replace gdp_def=2.575 if t==2006
replace gdp_def=3.170 if t==2007
*/

gen gap_k=VMPK-r_rate
gen abs_G_k=abs(gap_k)
gen lnabs_k=log(abs_G_k)
bysort newid: egen exp_max=max(export_intensity)
drop if exp_max==1  
gen ddd_export=did * d_export
* xtset newid t
 egen provyear=group(province  t)
 egen ind2year=group(ind2  t)
 egen owneryear=group(QiuType  t)
 egen provowneryear=group(province QiuType  t)
 egen ind4year=group(ind4_adj  t)

capture drop ddd_export
gen indc_export=0
gen indc_export_new=0
replace indc_export=1 if export_intensity>0&(t==1999|t==2000|t==1998|t==2001)
replace indc_export_new=1 if export_intensity>0&(t>=2002)

bysort newid: egen indc_export1=max(indc_export)
bysort newid: egen indc_export2=max(indc_export_new)




gen ddd_export=did*indc_export1
gen ddd_export2=did*indc_export2
/*
bysort newid post: gen indc_n=_n==1
bysort newid: egen indc_exist=sum(indc_n)
*/



*egen ub1=pctile(absG),p(99)
*egen lb1=pctile(absG),p(1)

*replace did=0 if indc_export1==1
gen exp_post=indc_export1*post
gen exp_tpu=indc_export1*tpu
gen exp_post2=indc_export2*post

*drop if indc_export1==0&export_intensity>0
*--------------------------------------------------------------------

gen lnabsG_gdp=ln(absG_gdp)
/*
winsor2 tfp_op lnabs_k lnage  finance2  lnkL rate , replace cuts(1 99) trim
winsor2 lnRD, replace cuts(0 99) trim
drop if VMPL<0
*/
winsor2 lnabs_k  , replace cuts(1 99) trim
*******************************************************************************************************
*9.1 (column 1) firm and year fixed effects
reghdfe lnabs_k ddd_export did  Llnl Ltfp_op   Llnage  LlnkL  LlnRD  exp_post  export_intensity Lfinance2 exp_post ///
 Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind,  ///
absorb(t newid) cluster (ind4year)   
*----------------------------------------------------------------------------------------------------------
 *9.2. (column 2) prov-year and firm fe
reghdfe lnabs_k ddd_export did  Llnl Ltfp_op   Llnage  LlnkL  LlnRD  exp_post  export_intensity Lfinance2 exp_post ///
 Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind ,  ///
absorb(provyear newid) cluster (ind4year)   
*----------------------------------------------------------------------------------------------------------
 *9.3. (column 3) owner-year and firm fe
reghdfe lnabs_k ddd_export did  Llnl Ltfp_op   Llnage  LlnkL  LlnRD  exp_post  export_intensity Lfinance2 exp_post ///
 Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind ,  ///
absorb(owneryear newid) cluster (ind4year)   
*----------------------------------------------------------------------------------------------------------
 
*9.4 (column 4) prov-year+owner-year and firm fe
reghdfe lnabs_k ddd_export did  Llnl Ltfp_op   Llnage  LlnkL  LlnRD  exp_post  export_intensity Lfinance2 exp_post ///
 Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind ,  ///
absorb(provyear owneryear newid) cluster (ind4year)   
*----------------------------------------------------------------------------------------------------------
*9.5 (column 5) industry-year and firm fe
reghdfe lnabs_k ddd_export did  Llnl Ltfp_op   Llnage  LlnkL  LlnRD  exp_post  export_intensity Lfinance2 exp_post ///
 Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind ,  ///
absorb(ind2year newid) cluster (ind4year)   
 

*----------------------------------------------------------------------------------------------------------
 

* 9.6. (column 5) new exporters
reghdfe lnabs_k ddd_export2 did Llnl  Ltfp_op   Llnage  LlnkL  LlnRD    export_intensity Lfinance2 exp_post2 ///
 Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind if indc_export1==0,  ///
absorb(t newid) cluster (ind4year)   
 